package com.blog.dxxr.blogfront.Controller;

import com.blog.dxxr.blogfront.Common.contants.Contants;
import com.blog.dxxr.blogfront.Domain.ArticleWithBLOBs;
import com.blog.dxxr.blogfront.Service.ArticleService;
import com.blog.dxxr.blogfront.Service.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class IndexController {
    @Autowired
    private ArticleService articleService;
    @Autowired
    private WebService webService;

    //跳转到首页
    @RequestMapping("/")
    public String toIndex(HttpSession session){
        if (session.getAttribute(Contants.SESSION_VISITOR) == null){
            session.setAttribute(Contants.SESSION_VISITOR,"visitor");
            webService.updateWebBrowseTotal();
        }
        return "index";
    }

    //跳转到博客详情页面
    @RequestMapping("/index/toBlogDetailPage.do")
    public String toBlogDetailPage(String id, Model model){
        ArticleWithBLOBs article = articleService.queryArticleById(id);
        model.addAttribute("article",article);
        return "blogDetails";
    }

    //跳转到个人主页
    @RequestMapping("/index/toSelfPage.do")
    public String toSelfPage(){
        return "self";
    }

    //跳转到鸣谢页面
    @RequestMapping("/index/toThankPage.do")
    public String toThankPage(){
        return "thank";
    }

    //跳转到404页面
    @RequestMapping("/index/toErrorPage.do")
    public String toErrorPage(){
        return "error";
    }
}
